@PACKAGE_INIT@

include(CMakeFindDependencyMacro)

set_and_check(DWARFS_INCLUDE_DIR "@PACKAGE_CMAKE_INSTALL_INCLUDEDIR@")
set_and_check(DWARFS_CMAKE_DIR "@PACKAGE_DWARFS_CMAKE_INSTALL_DIR@")

set(DWARFS_PREFIX_DIR "${PACKAGE_PREFIX_DIR}")

find_package(PkgConfig)

if(@APPLE@ AND @USE_HOMEBREW_LIBARCHIVE@) # APPLE AND USE_HOMEBREW_LIBARCHIVE
  find_program(HOMEBREW_EXE brew)
  execute_process(
    COMMAND ${HOMEBREW_EXE} --prefix libarchive
    OUTPUT_VARIABLE LIBARCHIVE_PREFIX
    OUTPUT_STRIP_TRAILING_WHITESPACE)
  list(PREPEND CMAKE_PREFIX_PATH ${LIBARCHIVE_PREFIX})
endif()

find_dependency(Threads REQUIRED)
find_dependency(fmt CONFIG REQUIRED)
find_dependency(gflags CONFIG REQUIRED)
find_dependency(Boost @BOOST_REQUIRED_VERSION@ REQUIRED CONFIG
                COMPONENTS chrono context filesystem program_options regex thread
                OPTIONAL_COMPONENTS process system)
pkg_check_modules(LIBCRYPTO REQUIRED IMPORTED_TARGET libcrypto>=@LIBCRYPTO_REQUIRED_VERSION@)
pkg_check_modules(LIBARCHIVE REQUIRED IMPORTED_TARGET libarchive>=@LIBARCHIVE_REQUIRED_VERSION@)
pkg_check_modules(XXHASH REQUIRED IMPORTED_TARGET libxxhash>=@XXHASH_REQUIRED_VERSION@)
pkg_check_modules(ZSTD REQUIRED IMPORTED_TARGET libzstd>=@ZSTD_REQUIRED_VERSION@)

set(LIBDWARFS_WITH_CPPTRACE @cpptrace_FOUND@)
set(LIBDWARFS_WITH_LIBLZ4 @LIBLZ4_FOUND@)
set(LIBDWARFS_WITH_LIBLZMA @LIBLZMA_FOUND@)
set(LIBDWARFS_WITH_LIBBROTLI (@LIBBROTLIDEC_FOUND@ AND @LIBBROTLIENC_FOUND@))
set(LIBDWARFS_WITH_FLAC @FLAC_FOUND@)
set(LIBDWARFS_WITH_JEMALLOC @JEMALLOC_FOUND@)

if(LIBDWARFS_WITH_CPPTRACE)
  find_dependency(cpptrace CONFIG REQUIRED)
endif()

if(LIBDWARFS_WITH_LIBLZ4)
  pkg_check_modules(LIBLZ4 REQUIRED IMPORTED_TARGET liblz4>=@LIBLZ4_REQUIRED_VERSION@)
endif()

if(LIBDWARFS_WITH_LIBLZMA)
  pkg_check_modules(LIBLZMA REQUIRED IMPORTED_TARGET liblzma>=@LIBLZMA_REQUIRED_VERSION@)
endif()

if(LIBDWARFS_WITH_LIBBROTLI)
  pkg_check_modules(LIBBROTLIDEC REQUIRED IMPORTED_TARGET libbrotlidec>=@LIBBROTLI_REQUIRED_VERSION@)
  pkg_check_modules(LIBBROTLIENC REQUIRED IMPORTED_TARGET libbrotlienc>=@LIBBROTLI_REQUIRED_VERSION@)
endif()

if(LIBDWARFS_WITH_FLAC)
  pkg_check_modules(FLAC REQUIRED IMPORTED_TARGET flac++>=@FLAC_REQUIRED_VERSION@)
endif()

if(LIBDWARFS_WITH_JEMALLOC)
  pkg_check_modules(JEMALLOC REQUIRED IMPORTED_TARGET jemalloc>=@JEMALLOC_REQUIRED_VERSION@)
endif()

if (NOT TARGET dwarfs::dwarfs_common)
  include("${DWARFS_CMAKE_DIR}/dwarfs-targets.cmake")
endif()

check_required_components(dwarfs)
